package cn.openea.perpartner.meily.web.service.impl;

import cn.openea.perpartner.meily.web.entity.Role;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.openea.perpartner.meily.web.mapper.UserRoleMapper;
import cn.openea.perpartner.meily.web.entity.UserRole;
import cn.openea.perpartner.meily.web.service.IUserRoleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户和角色关联表(UserRole)表服务实现类
 *
 * @author Weird077
 * @since 2023-03-15 16:17:55
 */
@Service("userRoleService")
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements IUserRoleService {

    @Override
    public boolean deleteUserRoleByUserId(String userId) {
        LambdaQueryWrapper<UserRole> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserRole::getUserId, userId);
        return remove(wrapper);
    }

    @Override
    public boolean deleteUserRoleInfo(UserRole userRole) {
        LambdaQueryWrapper<UserRole> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserRole::getUserId, userRole.getUserId());
        wrapper.eq(UserRole::getRoleId, userRole.getRoleId());
        return remove(wrapper);
    }

    @Override
    public boolean deleteUserRoleInfos(Long roleId, List<String> userIdList) {
        LambdaQueryWrapper<UserRole> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserRole::getRoleId, roleId);
        wrapper.in(UserRole::getUserId,userIdList);
        return remove(wrapper);
    }

    /**
     * 根据userId获取roleId
     */
    @Override
    public List<UserRole> getAllRoleIdByUserId(String userId) {
        LambdaQueryWrapper<UserRole> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserRole::getUserId, userId);
        return list(wrapper);
    }
}

